package com.lemon.smartsafetynew.ui.adapter.record;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafetynew.entity.air.AirItmeVo;
import com.lemon.smartsafetynew.util.common.CommonUtil;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by Andrew on 2018/3/19.
 */

public class AirAdapter extends LemonRcvAdapter<AirItmeVo> {

    private RecyclerTClickListener<AirItmeVo> mListener;

    public AirAdapter(@Nullable List<AirItmeVo> data, RecyclerTClickListener<AirItmeVo> mListener) {
        super(data);
        this.mListener = mListener;
    }

    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new ItemAdapter();
    }

    public class ItemAdapter implements AdapterItem<AirItmeVo> {

        private AirItmeVo data;
        private int pos;

        @Bind(R.id.tv_num)
        TextView tvNum;
        @Bind(R.id.tv_name)
        TextView tvName;
        @Bind(R.id.tv_type)
        TextView tvType;
        @Bind(R.id.ll)
        LinearLayout ll;

        @Override
        public int getLayoutResId() {
            return R.layout.layout_air_adapter;
        }

        @Override
        public void bindViews(View root) {
            ButterKnife.bind(this, root);
        }

        @Override
        public void setViews() {
            ll.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mListener.onItemClick(data, pos);
                }
            });
        }

        @Override
        public void handleData(AirItmeVo airItmeVo, int position) {

            data = airItmeVo;
            pos = position;
           if(!TextUtils.isEmpty(airItmeVo.getOrder())){
                tvNum.setText(airItmeVo.getOrder());
            }

          if(!TextUtils.isEmpty(airItmeVo.getName())){
                tvName.setText(airItmeVo.getName());
            }

            tvType.setText(CommonUtil.avoidNullString(airItmeVo.getType()));
        }

    }
}
